package org.gw.ylc.base.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class RequestExceptionHandlerResolver extends DefaultHandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		if (ex instanceof RequestMessageException) {
			response.setStatus(500);
			return new ModelAndView(new TextView(ex.getMessage()));
		}
		return super.resolveException(request, response, handler, ex);
	}

}
